home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Jul
/
di9807rl
/
stdform.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-02-26
|
3KB
|
116 lines
unit StdForm;
// Display a table of the 20 standard Windows colors.
// Copyright ⌐ 1998 Tempest Software, Inc.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, Menus;
type
TStandardColorForm = class(TForm)
Grid: TStringGrid;
PopupMenu: TPopupMenu;
EditCopy: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure GridDrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect;
State: TGridDrawState);
procedure EditCopyClick(Sender: TObject);
private
procedure DefineColor(Row: Integer; Name: string);
end;
var
StandardColorForm: TStandardColorForm;
implementation
uses ClipBrd;
{$R *.DFM}
// Column indices in the grid.
const
colColor = 0;
colName = 1;
colLiteral = 2;
colRGB = 3;
// Get the definition of a standard Windows color. The Row argument
// is the row number in the grid. The palette index is Row-1.
procedure TStandardColorForm.DefineColor(Row: Integer; Name: string);
var
Color: TColor;
Ident: string;
begin
Color := GetNearestColor(Canvas.Handle, PaletteIndex(Row-1));
Grid.Cells[colName, Row] := Name;
if ColorToIdent(Color, Ident) then
Grid.Cells[colLiteral, Row] := Ident;
Grid.Cells[colRGB, Row] := Format('$%6.6x', [Color]);
end;
procedure TStandardColorForm.FormCreate(Sender: TObject);
begin
Grid.Cells[colColor, 0] := 'Color';
Grid.Cells[colName, 0] := 'Name';
Grid.Cells[colLiteral, 0] := 'Delphi Literal';
Grid.Cells[colRGB, 0] := 'RGB';
// Set up the names of the standard Windows colors.
DefineColor(1, 'Black');
DefineColor(2, 'Maroon');
DefineColor(3, 'Dark Green');
DefineColor(4, 'Olive');
DefineColor(5, 'Navy Blue');
DefineColor(6, 'Purple');
DefineColor(7, 'Teal');
DefineColor(8, 'Light Gray');
DefineColor(9, 'Light Green');
DefineColor(10, 'Light Blue');
DefineColor(11, 'Cream');
DefineColor(12, 'Medium Gray');
DefineColor(13, 'Dark Gray');
DefineColor(14, 'Red');
DefineColor(15, 'Bright Green');
DefineColor(16, 'Yellow');
DefineColor(17, 'Blue');
DefineColor(18, 'Magenta');
DefineColor(19, 'Cyan');
DefineColor(20, 'White');
end;
// Draw the left-most column of the grid by filling the cell
// with the actual color.
procedure TStandardColorForm.GridDrawCell(Sender: TObject; Col,
Row: Integer; Rect: TRect; State: TGridDrawState);
begin
if (Col = colColor) and (Row > 0) then
begin
Grid.Canvas.Brush.Color := PaletteIndex(Row-1);
Grid.Canvas.FillRect(Rect);
end;
end;
// Copy the text of the table to the clipboard, separating
// columns with tabs, and rows with CR-LF line endings.
procedure TStandardColorForm.EditCopyClick(Sender: TObject);
const
TAB = ^I;
RETURN = ^M^J;
var
Text: string;
Row: Integer;
begin
Text := '';
for Row := 1 to 21 do
Text := Text + Grid.Cells[colName,Row] + TAB +
Grid.Cells[colLiteral,Row] + TAB +
Grid.Cells[colRGB,Row] + RETURN;
Clipboard.AsText := Text;
end;
end.